package com.xukai.springboot.service.statistics;

import com.xukai.springboot.datalayer.statis.StatisPlayMapper;
import com.xukai.springboot.entity.statistics.t_statis_play_item;
import com.xukai.springboot.entity.statistics.t_statis_play_main;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StatisPlayService {

    @Autowired
    StatisPlayMapper statisPlayMapper;

    /**
     * 获取播放列表
     */
    public List<t_statis_play_main> GetPlayList(String name, int state, int start, int pageSize) {
        return statisPlayMapper.GetPlayList(name, state, start, pageSize);
    }


    /**
     * 获取播放列表基本信息
     */
    public t_statis_play_main GetPlay(int id) {
        return statisPlayMapper.GetPlay(id);
    }


    /**
     * 新建播放列表
     */
    public void AddPlay(t_statis_play_main data) {
        data.setCreateTime(new Date());
        statisPlayMapper.AddPlay(data);
    }

    /**
     * 修改播放列表基本信息
     */
    public void UpdatePlay(t_statis_play_main data) {
        statisPlayMapper.UpdatePlay(data);
    }

    /**
     * 删除播放列表基本信息
     */
    public void DelPlay(int id) {
        statisPlayMapper.DelPlay(id);
    }

    /**
     * 获取播放列表数据总数
     */
    public int GetPlayCount(String name, int state) {
        return statisPlayMapper.GetPlayCount(name, state);
    }

    /**
     * 获取场景列表
     */
    public List<t_statis_play_item> GetPlayItemList(int id, int start, int pageSize) {
        return statisPlayMapper.GetPlayItemList(id, start, pageSize);
    }

    /**
     * 添加场景
     */
    public t_statis_play_item AddPlayItem(t_statis_play_item data) {
        int count = statisPlayMapper.sceneIsExist(data.getSceneID(), data.getMainID());
        if (count == 0) {
            int sort = statisPlayMapper.GetItemMaxSort(data.getMainID());
            data.setSort(sort + 1);
            statisPlayMapper.AddPlayItem(data);
        }
        return data;
    }

    /**
     * 删除场景
     */
    public void DelPlayItem(int id) {
        statisPlayMapper.DelPlayItem(id);
    }

    /**
     * 获取场景总数
     */
    public int GetPlayItemCount(int id) {
        return statisPlayMapper.GetPlayItemCount(id);
    }

    /**
     * 修改排序
     */
    public void UpdateItemSort(int id, int sort) {
        statisPlayMapper.UpdateItemSort(id, sort);
    }

    /**
     * 验证播放列表名称是否存在
     *
     * @param id
     * @param name
     * @return
     */
    public boolean IsExit(int id, String name) {

        int count = statisPlayMapper.IsExist(id, name);
        if (count > 0) {
            return true;
        }
        return false;
    }

}
